import {createRouter, createWebHistory} from 'vue-router'

//导入组件
import login from '@/views/user/longin.vue'
import userBook from '@/views/user/userBook.vue'
import creatingUser from '@/views/user/creatingUser.vue'
import admin from '@/views/admin/admin.vue'
import adminLogin from '@/views/admin/login.vue'
import bookManagement from '@/views/admin/books/bookManagement.vue'
import bookCategories from '@/views/admin/books/bookCategories.vue'
import bookLendingManagement from '@/views/admin/books/bookLendingApproval.vue'
import userBorrowingHistory from '@/views/admin/users/userBorrowingHistory.vue'
import userManagement from '@/views/admin/users/userManagement.vue'
import adminManagement from '@/views/admin/users/adminManagement.vue'
import adminProfile from '@/views/admin/users/adminProfile.vue'
import roleManagement from '@/views/admin/users/roleManagement.vue'
import statisticsPanel from '@/views/admin/statistics/statisticsPanel.vue'
import BorrowingTrend from '@/views/admin/statistics/components/BorrowingTrend.vue'
import CategoryStats from '@/views/admin/statistics/components/CategoryStats.vue'
import PopularBooks from '@/views/admin/statistics/components/PopularBooks.vue'
import InventoryStatus from '@/views/admin/statistics/components/InventoryStatus.vue'
import Dashboard from '@/views/admin/statistics/components/Dashboard.vue'
import DataExport from '@/views/admin/statistics/components/DataExport.vue'
import changePassword from '@/views/admin/users/changePassword.vue'

//定义路由关系
const routes = [
    {path: '/', component: login},
    {path: '/userBook', component: userBook},
    {path: '/creatingUser', component: creatingUser},
    {path: '/adminLogin', component: adminLogin},
    {
        path: '/admin', component: admin,
        children: [
            {path: '/admin/bookManagement', component: bookManagement},
            {path: '/admin/bookCategories', component: bookCategories},
            {path: '/admin/bookLendingManagement', component: bookLendingManagement},
            {path: '/admin/userBorrowingHistory', component: userBorrowingHistory},
            {path: '/admin/userManagement', component: userManagement},
            {path: '/admin/adminManagement', component: adminManagement},
            {path: '/admin/adminProfile', component: adminProfile, meta: { title: '个人中心' }},
            {path: '/admin/roleManagement', component: roleManagement},
            {path: '/admin/changePassword', component: changePassword, meta: { title: '修改密码' }},
            {path: '/admin/statistics', 
             component: statisticsPanel, 
             meta: { title: '借阅数据统计' },
             redirect: '/admin/statistics/dashboard',
             children: [
               {
                 path: 'dashboard',
                 name: 'Dashboard',
                 component: Dashboard,
                 meta: { title: '综合数据看板' }
               },
               {
                 path: 'borrowing-trend',
                 name: 'BorrowingTrend',
                 component: BorrowingTrend,
                 meta: { title: '借阅趋势分析' }
               },
               {
                 path: 'category-stats',
                 name: 'CategoryStats',
                 component: CategoryStats,
                 meta: { title: '图书分类统计' }
               },
               {
                 path: 'popular-books',
                 name: 'PopularBooks',
                 component: PopularBooks,
                 meta: { title: '热门图书分析' }
               },
               {
                 path: 'inventory-status',
                 name: 'InventoryStatus',
                 component: InventoryStatus,
                 meta: { title: '库存状态分析' }
               },
               {
                 path: 'data-export',
                 name: 'DataExport',
                 component: DataExport,
                 meta: { title: '数据导出' }
               }
             ]
            },
        ]
    },
    {
        path: '/user',
        component: () => import('@/views/user/userBook.vue'),
        children: [
            {
                path: 'book-detail',
                name: 'BookDetail',
                component: () => import('@/views/user/bookDetail.vue')
            },
            {
                path: 'search-results',
                name: 'SearchResults',
                component: () => import('@/views/user/searchResults.vue'),
                props: (route) => ({ keyword: route.query.keyword }),
                meta: { title: '搜索结果' }
            }
        ]
    },
    {
        path: '/user/book-detail',
        name: 'BookDetail',
        component: () => import('@/views/user/bookDetail.vue')
    },
    {
        path: '/user/categories',
        name: 'BookCategories',
        component: () => import('@/views/user/bookCategories.vue'),
        meta: {
            title: '图书分类',
            requiresAuth: true
        }
    },
    {
        path: '/user/ranking',
        name: 'BookRanking',
        component: () => import('@/views/user/bookRanking.vue'),
        meta: { title: '小说排行榜' }
    },
    {
        path: '/user/author-books',
        name: 'AuthorBooks',
        component: () => import('@/views/user/authorBooks.vue'),
        meta: { title: '作者作品' }
    },
    {
        path: '/user/borrowing-history',
        name: 'BorrowingHistory',
        component: () => import('@/views/user/borrowingHistory.vue'),
        meta: { 
            title: '借阅历史',
            requiresAuth: true
        }
    }
]

//创建路由器
const router = createRouter({
    history: createWebHistory(import.meta.env.BASE_URL),
    routes: routes
})

export default router
